package com.sanbi.common.util;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

public class EncodeUtil {
    public static String encode(String content) {
        return encode(content, "UTF-8");
    }

    public static String decode(String content){
        return decode(content, "UTF-8");
    }

    private static String encode(String content, String charset) {
        try {
            return URLEncoder.encode(content, charset);
        } catch (UnsupportedEncodingException var3) {
            throw new RuntimeException(var3);
        }
    }

    private static String decode(String content, String charset) {
        try {
            return URLDecoder.decode(content, charset);
        } catch (UnsupportedEncodingException var3) {
            throw new RuntimeException(var3);
        }
    }

    public static void main(String[] args) {
        String str="{\n" +
                "  \"address\": \"xxx\",\n" +
                "  \"username\": \"111\"\n" +
                "}";
        System.out.println("initial string: "+str);

        str=encode(str);
        System.out.println("encode string: "+str);

        str=decode(str);
        System.out.println("decode string: "+str);

    }


}
